package com.wzh.design.flyweight.demo1;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.FutureTask;

/**
 * @description: 享元模式
 * @author: WZH
 * @time: 2021/6/21 16:41
 */
public class FlyweightFactory {
    private Map<Character, Flyweight> files = new HashMap<Character, Flyweight>();

    public Flyweight factory(Character state) {
        //先从已有的缓存列表中查询对象是否已存在
        Flyweight flyweight = files.get(state);
        if (flyweight == null) {
            //如果对象不存在，则重新创建一个新的Flyweight对象
            flyweight = new ConcreteFlyweight(state);
            //将新生成的对象放入缓存列表中
            files.put(state, flyweight);
        }
        //返回对象
        return flyweight;
    }


}